package com.hui.service.impl;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hui.entity.dao.StoreOrderCartInfo;
import com.hui.entity.vo.StoreCartQueryVo;
import com.hui.mapper.StoreOrderCartInfoMapper;
import com.hui.service.StoreOrderCartInfoService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单购物详情表(StoreOrderCartInfo)表服务实现类
 *
 * @author hui
 * @since 2022-08-04 18:30:19
 */
@Service("storeOrderCartInfoService")
public class StoreOrderCartInfoServiceImpl extends ServiceImpl<StoreOrderCartInfoMapper, StoreOrderCartInfo> implements StoreOrderCartInfoService {

    /**
     * 生成订单详情
     *
     * @param oid
     * @param cartInfo
     */
    @Override
    public void saveCartInfo(Long oid, List<StoreCartQueryVo> cartInfo) {
        List<StoreOrderCartInfo> list = new ArrayList();

        for (StoreCartQueryVo cart : cartInfo) {
            StoreOrderCartInfo info = new StoreOrderCartInfo();
            info.setOid(oid);
            info.setCartId(cart.getId());
            info.setProductId(cart.getProductId());
            info.setCartInfo(JSONObject.toJSON(cart).toString());
            info.setUnique(IdUtil.simpleUUID());
            list.add(info);
        }

        this.saveBatch(list);
    }
}

